import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
enum Api {
  SysUserApi = '/sysUser',
}
/**
 * 查询系统用户表分页
 * @author frank
 * @date 2022-09-05 17:53:03
 */
export const getSysUserPage = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: Api.SysUserApi + '/page', params });
/**
 * 查询系统用户详情
 * @author frank
 * @date 2022-09-05 17:53:03
 */
export const detail = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: Api.SysUserApi + '/detail', params });
/**
 * 添加系统用户表
 * @author frank
 * @date 2022-09-05 17:53:03
 */
export const addSysUser = (params?: any) => defHttp.post({ url: Api.SysUserApi + '/add', params });
/**
 * 修改系统用户表
 * @author frank
 * @date 2022-09-05 17:53:03
 */
export const editSysUser = (params?: any) => defHttp.post({ url: Api.SysUserApi + '/edit', params });

export const deactivateSysUser = (id: string) =>
  defHttp.post({ url: `${Api.SysUserApi}/deactivate/${id}` });

export const enableSysUser = (id: string) =>
  defHttp.post({ url: `${Api.SysUserApi}/enable/${id}` });
/**
 * 删除系统用户表-修改状态
 * @author frank
 * @date 2022-09-05 17:53:03
 */
export const changeSysUserStatus = (id: string, status: string) =>
  defHttp.post({ url: Api.SysUserApi + '/changeStatus', params: { status, id } });
/**
 * 导出系统用户表
 * @author frank
 * @date 2022-09-05 17:53:03
 */
export const exportSysUser = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: Api.SysUserApi + '/export', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
